package com.zyy.smartcity1129.reservation;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.ReserDBInfo;
import com.zyy.smartcity1129.util.RvAd;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: ReserManageFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 30/11/2021$
 * @Version: 1.0
 */
public class ReserManageFragment extends BaseFragment {
    private Button btnReserNowAdd;
    private RecyclerView rvReserManage;
    List<ReserDBInfo> infoList = new ArrayList<>();
    RvAd<ReserDBInfo> rvAd;
    private TextView tvReserManage;
    private RecyclerView rvReserNow;

    @Override
    protected int layId() {
        return R.layout.f_reser_now;
    }

    @Override
    protected String title() {
        return null;
    }

    @Override
    protected boolean back() {
        return false;
    }

    @Override
    protected Boolean bottom() {
        return null;
    }

    @Override
    protected void init(View iv) {
        ReservationFragment.mutableLiveData.postValue("车辆管理");
        initView(iv);
        initDataList();
        if (infoList.size() == 0) {
            rvReserManage.setVisibility(View.GONE);
            tvReserManage.setVisibility(View.VISIBLE);
        } else {
            tvReserManage.setVisibility(View.GONE);
            rvReserManage.setVisibility(View.VISIBLE);
            initAdapter(infoList);
            rvReserManage.setLayoutManager(new LinearLayoutManager(getContext()));
            rvReserManage.setAdapter(rvAd);
        }
    }

    private void initAdapter(List<ReserDBInfo> infoList) {
        rvAd = new RvAd<ReserDBInfo>(infoList, R.layout.r_reser_now) {
            private void initView(View vi) {
                tvRvPlateNo = (TextView) vi.findViewById(R.id.tvRvPlateNo);
                tvRvType = (TextView) vi.findViewById(R.id.tvRvType);
                tvRvTravelDistance = (TextView) vi.findViewById(R.id.tvRvTravelDistance);
                tvRvPhonenumber = (TextView) vi.findViewById(R.id.tvRvPhonenumber);
                imgRvReserNowDel = (ImageView) vi.findViewById(R.id.imgRvReserNowDel);
                lineRvReserNow = (LinearLayout) vi.findViewById(R.id.lineRvReserNow);
                imgRvReserNowDel.setVisibility(View.GONE);
                tvRvPhonenumber.setVisibility(View.GONE);
            }

            private TextView tvRvPhonenumber;
            private TextView tvRvTravelDistance;
            private TextView tvRvType;
            private TextView tvRvPlateNo;
            private ImageView imgRvReserNowDel;
            private LinearLayout lineRvReserNow;

            @Override
            protected void initR(View vi, ReserDBInfo info, int p) {
                initView(vi);
                tvRvPlateNo.setText("车牌号：" + info.getPlateNo());
                tvRvType.setText("预约时间：" + info.getTime());
                tvRvTravelDistance.setText("预约检车地点：" + info.getAddress());
            }
        };
    }

    private void initDataList() {
        infoList = new ReserDataAdapter().queryAll(getContext());
    }

    private void initView(View iv) {
        btnReserNowAdd = (Button) iv.findViewById(R.id.btnReserNowAdd);
        rvReserManage = (RecyclerView) iv.findViewById(R.id.rvReserNow);
        btnReserNowAdd.setVisibility(View.GONE);
        tvReserManage = (TextView) iv.findViewById(R.id.tvReserManage);
    }
}
